package com.wjpeng.wms.util;

import lombok.Getter;
import lombok.Setter;

import java.util.List;

@Setter @Getter
public class PageResult {
    private List<?> list;
    private Integer totalCount;

    private Integer currentPage;
    private Integer pageSize;

    private Integer totalPage;
    private Integer prevPage;
    private Integer nextPage;

    public PageResult(List<?> list, Integer totalCount, Integer currentPage, Integer pageSize) {
        this.list = list;
        this.totalCount = totalCount;
        this.currentPage = currentPage;
        this.pageSize = pageSize;

        if(totalCount <= pageSize){
            totalPage = 1;
            prevPage = 1;
            nextPage = 1;
            return;
        }

        totalPage = totalCount % pageSize == 0 ? totalCount / pageSize : totalCount / pageSize +1;
        prevPage = currentPage > 1 ? currentPage - 1 : 1;
        nextPage = currentPage < totalPage ? currentPage + 1 : totalPage;
    }
}
